package com.gombe.credit.app.ui.dialog

import android.content.Context
import android.text.SpannableString
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.gombe.credit.app.GombeCreditApp
import com.gombe.credit.app.R
import com.gombe.credit.app.common.CommonDialog
import com.gombe.credit.app.databinding.DialogGombeCreditReloadBinding
import com.gombe.credit.app.event.GombeCreditEventPointType
import com.gombe.credit.app.utils.GombeCreditDensityUtil

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：重新加载dialog
 */
class DialogGombeCreditReload: CommonDialog {

    private lateinit var binding: DialogGombeCreditReloadBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    override fun initGombeCreditWindow() {
        val params = window?.attributes
        params?.width = GombeCreditApp.app.getPhoneWidth() - GombeCreditDensityUtil.dp2px(48f)
        params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.attributes = params
        window?.setWindowAnimations(R.style.dialog_scale_anim) //修改动画样式
        window?.setGravity(Gravity.CENTER)
    }

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String) : super(context) {
        eventRemark = remark
    }
    constructor(context: Context, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun takeGombeCreditRootView(): View {
        binding = DialogGombeCreditReloadBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initGombeCreditView() {
    }

    override fun initGombeCreditListener() {
        setOnClickListener(binding.buttonReload) //ok
    }

    override fun takeGombeCreditData() {
    }

    override fun onGombeCreditViewClick(v: View?) {
        dismiss()
        if (v?.id == R.id.buttonReload){
            addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_CLICK.NET_RELOAD,eventRemark)
            mCallback?.onClick(v)
        }
    }

    /**
     * 设置埋点备注
     */
    fun addGombeCreditKindTipsEventRemark(remark: String){
        eventRemark = remark
    }

    /**
     * 设置提示图标
     */
    fun setGombeCreditKindTipsIconResource(resId: Int){
        binding.imgKindIcon.setImageResource(resId)
    }

    /**
     * 设置提示语
     */
    fun setGombeCreditKindTipsMsgText(tips: String){
        binding.textKindTips.text = tips
    }

    /**
     * 设置提示语
     */
    fun setGombeCreditKindTipsMsgText(spannableString: SpannableString){
        binding.textKindTips.text = spannableString
    }

    /**
     * 设置提示语对齐方式
     */
    fun setGombeCreditKindTipsMsgGravity(gravity: Int){
        binding.textKindTips.gravity = gravity
    }

    /**
     * 设置ok文字
     */
    fun setGombeCreditKintTipsButtonConfirmText(text: String){
        binding.buttonReload.text = text
    }

    /**
     * 设置ok按钮背景
     */
    fun setGombeCreditKindTipsButtonConfirmBackgroundResource(color: Int){
        binding.buttonReload.shapeDrawableBuilder.setSolidColor(color).intoBackground()
    }

    /**
     * 设置两个按钮背景
     */
    fun setGombeCreditKindTipsButtonDoubleBackgroundResource(cancelColor: Int, okColor: Int){
        binding.buttonReload.shapeDrawableBuilder.setSolidColor(okColor).intoBackground()
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_DIALOG.NET_RELOAD_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_DIALOG.NET_RELOAD_DISMISS,eventRemark)
    }
}